import {
	jsonp
} from 'vue-jsonp'; //安装完成组件引用
import QQMapWX from "@/utils/map/qqmap-wx-jssdk.js"


export function getLocation() {
	let that = this;
	const key = "7WVBZ-KCTCF-JXIJD-JDXRH-SDHCQ-KKF5J" // 替换为你的高德、百度或腾讯地图API的key



	return new Promise((resolve) => {

		//位置信息默认数据
		let location = {
			longitude: 0,
			latitude: 0,
			province: "",
			city: "",
			area: "",
			street: "",
			address: "",
		};
		uni.getLocation({
			type: "gcj02",
			success(res) {
				location.longitude = res.longitude;
				location.latitude = res.latitude;
				resolve(location);
				// 腾讯地图Api
				const qqmapsdk = new QQMapWX({
					key: key //这里填写自己申请的key
				});
				qqmapsdk.reverseGeocoder({
					location,
					success(response) {
						let info = response.result;

						location.province = info.address_component
							.province;
						location.city = info.address_component.city;
						location.area = info.address_component.district;
						location.street = info.address_component.street;
						location.address = info.address;
						resolve(location);
					},
				});
			},
			fail(err) {
				console.log(err)
				resolve(location);
			},
		});




	});

}